home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / PROGRAMMING / DESKLIBC / SOURCES.ZIP / DeskLib / !DLSources / Libraries / Misc / s / Dispatch
Text File  |  1995-08-26  |  2KB  |  62 lines

  1. ;   ####             #    #     # #
  2. ;   #   #            #    #       #          The FreeWare C library for
  3. ;   #   #  ##   ###  #  # #     # ###             RISC OS machines
  4. ;   #   # #  # #     # #  #     # #  #   ___________________________________
  5. ;   #   # ####  ###  ##   #     # #  #
  6. ;   #   # #        # # #  #     # #  #    Please refer to the accompanying
  7. ;   ####   ### ####  #  # ##### # ###    documentation for conditions of use
  8. ;   ________________________________________________________________________
  9. ;
  10. ;   File:    Misc.Dispatch.s
  11. ;   Author:  Copyright © 1993 Shaun Blackmore
  12. ;   Version: 1.00 (03 Apr 1993)
  13. ;   Purpose: See below
  14.  
  15.         GET     ^.h.regdefs
  16.         GET     ^.h.swinos
  17.         GET     ^.h.macros
  18.  
  19. ; int Dispatch(int value, int size, int *table, void *functions[], int arg0, int arg1, int arg2, int arg3)
  20.  
  21. ; Perform a table look up of value in table[size]
  22. ; call the corrseponding procedure in functions[size]
  23. ; with count arguments (0 <= count <= 4)
  24. ; If the table contains a -1 then this is always taken
  25. ;       - Use this for a default action
  26.  
  27.         IMPORT  |x$stack_overflow|
  28.         PREAMBLE
  29.         STARTCODE Dispatch
  30. ;
  31.         MOV     ip,sp
  32.         STMFD   sp!, {r4,r5,r6,r7,fp,ip,lr,pc}
  33.         SUB     fp,ip,#4
  34.         CMPS    sp,sl
  35.         BLLT    |x$stack_overflow|
  36.  
  37. Loop
  38.         LDR     r4,[r2,#0]
  39.         CMP     r4,r0
  40.         CMPNE   r4,#-1           ; Always match a -1
  41.         BEQ     Cont
  42.         ADD     r2,r2,#4        ; increase table
  43.         ADD     r3,r3,#4
  44.         SUBS    r1,r1,#1        ; Decrease count
  45.         BNE     Loop
  46.         MOV    r0,#-1
  47.         B       Exit
  48. Cont
  49.         LDR     r7,[r3,#0]      ; Load address into r7
  50.         TEQ     r7,#0
  51.         BEQ     Exit
  52.         LDR     r0,[ip,#0]
  53.         LDR     r1,[ip,#4]
  54.         LDR     r2,[ip,#8]
  55.         LDR     r3,[ip,#12]
  56.         MOV     lr,pc           ; Return after 2 instructions
  57.         MOV     pc,r7
  58. Exit
  59.         LDMEA   fp, {r4,r5,r6,r7,fp,sp,pc}^
  60. ;
  61.         END
  62.